package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.common.RedisUtils;
import cn.cs.service.AgentUserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/agentUser")
public class AgentUserController {
    @Resource
    private AgentUserService agentUserService;
    @Resource
    private RedisUtils redisUtils;
    /**
     * 用户登录
     * @param
     * @param
     *
     * */
    @RequestMapping(value = "/p/agentDologin", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Dto agentDologin(HttpServletRequest request) {
        Dto dto=null;
        try {
            dto=agentUserService.agentDologin(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /**
     * 用户登录
     * @param
     * @param
     *
     * */
    @RequestMapping(value = "/agentLoginOut", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public Dto agentLoginOut(HttpServletRequest request) {
        String token = request.getHeader("token");
        redisUtils.delete(token);
        return  DtoUtil.returnSuccess();
    }

    /****
     * 收益看板接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/agentProfit")
    @ResponseBody
    public Dto agentProfit(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            dto=agentUserService.agentProfit(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 查看排行接口
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getRank")
    @ResponseBody
    public Dto getRank(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.getRank(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 获取经销商管辖的所有区域
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentManageAreas")
    @ResponseBody
    public Dto getAgentManageAreas(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.getAgentManageAreas(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }


    /****
     * 获取收益明细
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentEarList")
    @ResponseBody
    public Dto getAgentEarList(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.getAgentEarList(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("获取失败","002");
        }
        return dto;
    }


    /****
     * 查看收益维修单详情
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getRepOrderDetail")
    @ResponseBody
    public Dto getRepOrderDetail(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.getRepOrderDetail(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("获取失败","002");
        }
        return dto;
    }

    /****
     * 获取经销商个人信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/getAgentInfo")
    @ResponseBody
    public Dto getAgentInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.getAgentInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("获取失败","002");
        }
        return dto;
    }
    /****
     * 更改经销商个人信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/updateAgentInfo")
    @ResponseBody
    public Dto updateAgentInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.updateAgentInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("获取失败","002");
        }
        return dto;
    }

    /****
     * 上传经销商身份证接口
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/uploadAgentIdCard")
    @ResponseBody
    public Dto uploadAgentIdCard(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.uploadAgentIdCard(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 经销商注册店铺接口
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/registerAgentShop")
    @ResponseBody
    public Dto registerAgentShop(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.registerAgentShop(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 去激活身份认证接口
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/actionPower")
    @ResponseBody
    public Dto actionPower(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.actionPower(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }

    /****
     * 查看身份认证信息接口
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/powerInfo")
    @ResponseBody
    public Dto powerInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.powerInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }
    /****
     * 查看发票信息接口
     * @param request
     * @param
     * @return
     */
    @RequestMapping("/invoiceInfo")
    @ResponseBody
    public Dto invoiceInfo(HttpServletRequest request, HttpServletResponse response){
        Dto dto=null;
        try {
            response.setHeader("Access-Control-Allow-Origin", "*");
            dto=agentUserService.invoiceInfo(request);
        }catch (Exception e){
            e.printStackTrace();
            return DtoUtil.returnFail("查询失败","002");
        }
        return dto;
    }
}
